package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.entity.Dict;
import com.atguigu.result.Result;
import com.atguigu.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @PACKAGE_NAME: com.atguigu.controller
 * @CLASSNAME: DictController
 * @AUTHOR: zhangsan
 * @DATE: 2024/4/26 10:38
 * @SINCE 17.0.7
 * @DESCRIPTION: DictController
 * 注意 @RestController=@ResponseBody + @Controller
 */
@Slf4j
@RestController
@RequestMapping("/dict")
public class DictController {
    @Reference
    private DictService dictService;

    @RequestMapping("/findListByDictCode/{dictCode}")
    public Result<List<Dict>> findListByDictCode(@PathVariable("dictCode") String dictCode) {
        if (null == dictCode || dictCode.isEmpty()) {
            return Result.fail();
        }
        List<Dict> dictList = dictService.findListByDictCode(dictCode);
        return Result.ok(dictList);
    }

    @RequestMapping("/findListByParentId/{id}")
    public Result<List<Dict>> findListByParentId(@PathVariable("id") Long id) {
        if (null == id) {
            return Result.fail();
        }
        List<Dict> dictList = dictService.findListByParentId(id);
        return Result.ok(dictList);
    }
}
